define('m/logger', function(require, exports, module) {

  var logHandler,
    filterLevel,
    indexLevel = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'OFF'],
    loggersByNameMap = {};

  logHandler = function(messages, level) {
    var hdlr = console.log;

    if (level) {
      messages[0] = '[' + level + '] ' + messages[0];
    }

    // Delegate through to custom warn/error loggers if present on the console.
    if (level === 'WARN' && console.warn) {
      hdlr = console.warn;
    } else if (level === 'ERROR' && console.error) {
      hdlr = console.error;
    } else if (level === 'INFO' && console.info) {
      hdlr = console.info;
    }

    Function.prototype.apply.call(hdlr, console, messages);
  };

  function enabledFor(level) {
    return indexLevel.indexOf(level) >= indexLevel.indexOf(filterLevel);
  }

  function invoke(level, msgArgs) {
    if (logHandler && enabledFor(level)) {

      logHandler(msgArgs, level);

      if (!loggersByNameMap[level]) {
        loggersByNameMap[level] = [];
      }
      loggersByNameMap[level].push(msgArgs);

    }
  }

  exports.get = function(name) {
    if (indexLevel.indexOf(name) === -1) {
      throw name + ' 暂不支持, 请使用 DEBUG|INFO|WARN|ERROR|OFF';
    }

    var loggersByName = loggersByNameMap[name],
      loggerByName,
      logger = [];
    if (!loggersByName) {
      return '';
    }

    for (var i = 0; i < loggersByName.length; i++) {
      loggerByName = Array.prototype.slice.call(loggersByName[i]);
      logger.push(loggerByName.join('/n'));
    }
    return logger.join('/n');
  };

  exports.setLevel = function(newLevel) {
    if (indexLevel.indexOf(newLevel) === -1) {
      throw newLevel + ' 暂不支持, 请使用 DEBUG|INFO|WARN|ERROR|OFF';
    }
    filterLevel = newLevel;
  };

  exports.setHandler = function(func) {
    if (typeof func === 'function') {
      logHandler = func;
    }
  };

  exports.debug = function() {
    invoke('DEBUG', arguments);
  };

  exports.info = function() {
    invoke('INFO', arguments);
  };

  exports.warn = function() {
    invoke('WARN', arguments);
  };

  exports.error = function() {
    invoke('ERROR', arguments);
  };

});

Mobird.logger = require('m/logger');
Mobird.debug = Mobird.logger.debug;
Mobird.info = Mobird.logger.info;
Mobird.warn = Mobird.logger.warn;
Mobird.error = Mobird.logger.error;
